package hotel.action;

import hotel.service.RoomService;
import hotel.service.ServiceManager;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
/**
 * This class Delete Room from DataBase
 * @author Alex
 *
 */
public class DeleteRoomAction extends Action 
{
	private static final Logger logger = Logger.getLogger(DeleteRoomAction.class);
	private static final String DELETEROOMACTION_ERROR = "Error in DeleteRoomAction:";
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
		    throws Exception 
		    {
			String mapper = ForwardActionTo.ERROR;
			int id;
			try
			{
				RoomService roomService = ServiceManager.getDefault().getRoomService();
				id = Integer.valueOf(request.getParameter("id"));
				roomService.deleteRoom(id);
				mapper = ForwardActionTo.SUCCESS;
		    }
			catch(NullPointerException e)
			{
				logger.error(DELETEROOMACTION_ERROR + e);
		 	}

				return mapping.findForward(mapper);
		    }

}
